package edu.hit.pact.pgse.timer;

import java.util.Timer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.hit.pact.pgse.crawler.CrawlerManager;
import edu.hit.pact.pgse.util.Globals;

public class CrawlerSpeedReportSche {
	protected Timer confTaskTimer;
	private Log logger;
	private CrawlerManager crawlerManager;
	
	public CrawlerSpeedReportSche(CrawlerManager crawlerManager){
		confTaskTimer = new Timer();
		
		logger = LogFactory.getLog(CrawlerSpeedReportSche.class);
		this.crawlerManager = crawlerManager;
	}
	
	public void scheduleSpeedReportTask(){
		SpeedReportTask speedReportTask = new SpeedReportTask(crawlerManager);
		
		confTaskTimer.scheduleAtFixedRate(speedReportTask, 1000, 1000);
		logger.info("scheduleConfReload");
	}
	
	public void reScheduleTask(String type){
		if (type.equals("conf")){
			logger.error("conf update interval reschedule");
			confTaskTimer.cancel();
			confTaskTimer = new Timer();
			scheduleSpeedReportTask();
		} else {
			logger.error("type wrong");
		}
	}
}
